/**
 * Created by Ji.wenjiang on 2016/8/27.
 */

function chooseSex() {
  return function (gender) {
    return gender=='0'?'男':'女';
  }
}
//pay type
function payType() {
  return function (type) {
    switch (type){
      case '1': return '自费';
      break;
      case '2': return '公费';
      break;
      case '3': return '住院';
      break;
    }
  }
}
//
function diseasePart() {
  return function (type) {
    switch (type){
      case '1': return '肺部';
        break;
      case '2': return '胸部';
        break;
      case '3': return '头部';
        break;
    }
  }
}
//
function presentStatus() {
  return function (status) {
    switch (status){
      case '1': return'注册';
      break;
      case '2': return'压模';
        break;
      case '3': return'定位';
        break;
      case '4': return'勾靶';
        break;
      case '5': return'计划';
        break;
      case '6': return'验证';
        break;
      case '7': return'交费';
        break;
      case '8': return'治疗';
        break;
      case '9': return'完成';
        break;
    }
  }
}

function dose() {
  return function (a,dose,index,treatIndex) {
   if(index<treatIndex){
     return dose;
   }else{
     return 'xxx';
   }
  }
}
function treatStatus() {
  return function (a,index,treatIndex) {
    if(index<treatIndex){
      return '完成';
    }else{
      return '未完成';
    }
  }
}

function drSignature() {
  return function (a,index,treatIndex,img) {
    if(index<treatIndex){
      return img;
    }else{
      return '';
    }
  }
}

function getGender(){
  return function(a,gender){
    if(gender == '1'){
      console.log('1');
      return '男';
    }else if(gender == '2'){
      return '女';
    }
  }
}

function selectSex() {
  return function (sex) {
    if (sex == 0) {
      return '男';
    }
    else if (sex == 1) {
      return '女'
    }
  }
}
function presentAge() {
  return function (birth) {

    if (birth == '') {
      return birth;
    }
    if(isNaN(birth)){
      return '';
    }
    var age;
    var aDate = new Date();
    var thisYear = aDate.getFullYear();
    var thisMonth = aDate.getMonth() + 1;
    var thisDay = aDate.getDate();

    var birthy = birth.substr(0, 4);
    var birthm = birth.substr(5, 1);
    var birthd = birth.substr(7, 1);

    if (thisMonth - birthm < 0) {
      age = thisYear - birthy - 1;
    } else if (thisMonth == birthm) {
      if (thisDay < birthd) {
        age = thisYear - birthy - 1;
      } else {
        age = thisYear - birthy;
      }
    } else {
      age = thisYear - birthy;
    }
    if (isNaN(age)) {
      return '';
    }
    return age + '岁';
  }
}
function showOptions(){
  return function(a,start,condition,end){
    if(start<=condition && condition<=end)
    {

      return true;
    }else{
      console.log(end);
      return false;
    }
  }
}

function getFa(){
  return function(type){
    switch (type){
      case '3D': return'text-navy';
        console.log('sd');
        break;
      case 'su': return'text-success';
        break;
      case 'in': return'text-info';
        break;
      case 'wa': return'text-warning';
        break;
      case 'da': return'text-danger';
        break;
      case 'pu': return'text-purple';
        break;
      /*
      case '8': return'治疗';
        break;
      case '9': return'完成';
        break;*/
    }
  }
}
function photoTime() {
  return function (studydate) {
    return studydate.substr(0, 4) + '-' + studydate.substr(4, 2)
      + '-' + studydate.substr(6, 2);
  }
}
//头像缩略图
function imageShow() {
  return function (imageid,thumb,sex) {
    return lm.environment().hostUrl + '/public/thumb/' + thumb+ '/' + sex;
  }
}
angular.module('inspinia')
  .filter('chooseSex',chooseSex)
  .filter('payType',payType)
  .filter('diseasePart',diseasePart)
  .filter('presentStatus',presentStatus)
  .filter('dose',dose)
  .filter('treatStatus',treatStatus)
  .filter('drSignature',drSignature)
  .filter('getGender',getGender)
  .filter('showOptions',showOptions)
  .filter('getFa',getFa)
  .filter('imageShow',imageShow)
  .filter('selectSex', selectSex)
  .filter('presentAge', presentAge)
  .filter('photoTime', photoTime)
